#include <QtGui/QApplication>
#include "mainwindow.h"
#include "pannableview.h"
#include <QDebug>
#include <QSymbianEvent>
#include <QWebFrame>

#if defined(Q_OS_SYMBIAN) && !defined(HAVE_NOKIAQTSDK)
#include <W32STD.H>
#include <aknappui.h>
#include <avkon.rsg>
#endif

class HybridFWApplication : public QApplication
{
public:

    HybridFWApplication(int & argc, char ** argv ) : QApplication(argc, argv) {}

#if defined(Q_OS_SYMBIAN) && !defined(HAVE_NOKIAQTSDK)
    bool symbianEventFilter ( const QSymbianEvent *event )
    {
    	// TODO: Refactor this to use signals. 
        if(event && event->windowServerEvent() && m_webFrame)
        {
            if( event->windowServerEvent()->Type() == EEventFocusLost)
                m_webFrame->evaluateJavaScript("widgetOnHide()");
            else if( event->windowServerEvent()->Type() == EEventFocusGained)
                m_webFrame->evaluateJavaScript("widgetOnShow()");
        }

        return false;
    }
#endif

    void setWebFrame(QWebFrame *webFrame) { m_webFrame = webFrame; }
private:
    QWebFrame *m_webFrame;
};

int main(int argc, char *argv[])
{
	HybridFWApplication a(argc, argv);
    
#if defined(Q_OS_SYMBIAN) && !defined(HAVE_NOKIAQTSDK)
    //CEikStatusPane* statusPane = STATIC_CAST( CAknAppUi*, CEikonEnv::Static()->EikAppUi())->StatusPane();
#if @full_screen_enabled
	// Full screen means no status pane
    //statusPane->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_EMPTY);
#else
	// For now, give only the usual status pane as an option
	//statusPane->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_USUAL);
#endif
#endif
    
    MainWindow w;
    a.setWebFrame(w.webFrame());

#if !@soft_keys_enabled
	// No soft keys means full screen
	w.showFullScreen();
#else
	w.showMaximized();
#endif

    return a.exec();
}
